<?php /*a:2:{s:57:"E:\source\EasyPeak\application\admin\view\user\index.html";i:1573303920;s:75:"E:\source\EasyPeak\application\admin\view\..\..\common\view\admin_base.html";i:1572404708;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href=" /test/static/fontawesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/test/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/test/static/admin/admin.css" media="all">
    <script src="/test/static/js/jquery.min.js"></script>
</head>
<body>
<script src="/test/static/layui/layui.js"></script>
<script>
    layui.use(['form'],function(){
        var form = layui.form;
        form.on('submit(reset)',function(){
            location.reload();
        })
    })
</script>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <button class="layui-btn layui-btn-warm">所有用户</button>
            <div class="layui-btn-group layui-form">
                <?php if(key_exists('admin/user/add',$btns)): ?>
                <a class="layui-btn openfrm" data-href="<?php echo url('admin/user/add'); ?>"><i class="layui-icon layui-icon-add"></i>增加</a>
                <?php endif; ?>
            </div>
            <table class="layui-table layui-form" id="table" lay-filter="datatable" lay-size="sm"></table>
        </div>
    </div>
</div>

<script type="text/html" id="actionTpl">
    <?php if(isset($btns['admin/user/groupuser'])): $btn = $btns['admin/user/groupuser']; ?>
    <a class="layui-btn layui-btn-xs groupuser" data-href="<?php echo url($btn['action']); ?>?id={{d.id}}"><i class="<?php echo htmlentities($btn['icon']); ?>"></i><?php echo htmlentities($btn['name']); ?></a>
    <?php endif; if(isset($btns['admin/user/edit'])): $btn = $btns['admin/user/edit']; ?>
    <a class="layui-btn layui-btn-xs openfrm" data-href="<?php echo url($btn['action']); ?>?id={{d.id}}"><i class="<?php echo htmlentities($btn['icon']); ?>"></i><?php echo htmlentities($btn['name']); ?></a>
    <?php endif; if(isset($btns['admin/user/remove'])): $btn = $btns['admin/user/remove']; ?>
    <a class="layui-btn layui-btn-xs removebtn" data-href="<?php echo url($btn['action']); ?>?id={{d.id}}"><i class="<?php echo htmlentities($btn['icon']); ?>"></i><?php echo htmlentities($btn['name']); ?></a>
    <?php endif; if(isset($btns['admin/user/setauth'])): $btn = $btns['admin/user/setauth']; ?>
    <a class="layui-btn layui-btn-xs setauth" data-href="<?php echo url($btn['action']); ?>?id={{d.id}}"><i class="<?php echo htmlentities($btn['icon']); ?>"></i><?php echo htmlentities($btn['name']); ?></a>
    <?php endif; if(isset($btns['admin/user/setgroup'])): $btn = $btns['admin/user/setgroup']; ?>
    <a class="layui-btn layui-btn-xs setgroup" data-href="<?php echo url($btn['action']); ?>?id={{d.id}}"><i class="<?php echo htmlentities($btn['icon']); ?>"></i><?php echo htmlentities($btn['name']); ?></a>
    <?php endif; ?>
</script>

<script>
    layui.use(['table','form'], function(){
        var table = layui.table;
        var form = layui.form;

        table.render({
            elem: '#table'
            ,url:"<?php echo url('admin/user/index'); ?>"
            ,cellMinWidth: 80
            ,cols: [[
                {type:'numbers'}
                ,{field:'id', title:'ID',width:60}
                ,{field:'username', title:'名称',width:220}
                ,{field:'truename', title:'真实姓名',width:220}
                ,{field:'action', title:'操作',templet: '#actionTpl', unresize: true}
            ]]
            ,page: true
            ,limit:20
            ,limits:[10,20,30,50]
            ,jump: function(obj, first){
                //obj包含了当前分页的所有参数，比如：
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                console.log(obj.limit); //得到每页显示的条数

                //首次不执行
                if(!first){
                    //do something
                }
            }
            ,response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": 200,
                    "msg": res.msg,
                    "data": res.data.list,
                    'count':res.data.count
                };
            }
            ,done: function(res, curr, count){
                $.bindactions();
            }
        });

        $.bindactions = function(){
            $(".openfrm").on('click',function(){
                var href = $(this).data('href');
                top.layer.open({
                    type: 2
                    ,title:'编辑框'
                    ,content: href
                    ,area: ['550px', '500px']
                });
            });

            $(".groupuser").on('click',function(){
                var href = $(this).data('href');
                top.layer.open({
                    type: 2
                    ,title:'编辑框'
                    ,content: href
                    ,area: ['650px', '560px']
                });
            })

            $(".setauth").on('click',function(){
                var href = $(this).data('href');
                top.layer.open({
                    type: 2
                    ,title:'编辑框'
                    ,content: href
                    ,btn: ['确定', '取消']
                    ,area: ['750px', '520px']
                    ,yes: function(index, layero){
                        var ids = [];
                        layero.find('iframe').contents().find('#tree-table').find('.cbx.layui-form-checked').each(function(){
                            ids.push($(this).parent().parent().data('id'));
                        });
                        $.post(href,{auth:ids},function(res){
                            console.log(res);
                        });
                        top.layer.close(index); //关闭弹层
                    }
                });
            });

            $(".setgroup").on('click',function(){
                var href = $(this).data('href');
                top.layer.open({
                    type: 2
                    ,title:'编辑框'
                    ,content: href
                    ,btn: ['确定', '取消']
                    ,area: ['650px', '540px']
                    ,yes: function(index, layero){
                        layero.find('iframe').contents().find('#layui-submit').trigger('click');
                    }
                });
            });

            $(".removebtn").on('click',function(){
                var url = $(this).data('href');
                top.layer.confirm("确定删除吗？此操作不能撤销！", {icon: 3, title:'提示'},
                    function(index){
                        top.layer.closeAll();
                        $.post(url,function(res){
                            layer.msg(res.msg,{
                                offset: '15px'
                                ,icon: 1
                                ,time: 1000
                            },function(){
                                document.location.reload();
                            });
                        });
                    },function (index) {
                        top.layer.close(index);
                    }
                );
            });
        }

    });
</script>

</body>
</html>